package com.jdls.controller;

import com.jdls.dao.Student;
import com.jdls.dao.User;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 嘉德罗斯
 * @date 2021/9/15
 */
@Controller
public class UserController {
    @RequestMapping("/show")
    @ResponseBody
    public String show(String name,int age){
        System.out.println("name = "+name);
        System.out.println("age = "+age);
        return "jdls";
    }
    @RequestMapping("/login")
    @ResponseBody
    public String login(User user){
        if("嘉德罗斯".equals(user.getUsername())&&"123".equals(user.getPassword())){
            return "true";
        }
        return "false";
    }
    @RequestMapping("get")
    @ResponseBody
    public String get(@RequestBody Student student){
        System.out.println(student);
        return "ok";
    }
    @RequestMapping("find")
    @ResponseBody
    public User findById(){
        User user = new User();
        user.setUsername("JDLS");
        user.setPassword("123");
        return user;
    }
    @RequestMapping("findAll")
    @ResponseBody
    public List<User> findAll(){
        List<User> users = new ArrayList<User>();
        users.add(new User("嘉德罗斯","123"));
        users.add(new User("格瑞","456"));
        return users;
    }
}
